<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/dialog2/js/dialog.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/css/dialog.css">
    <script src="/js/plugins/jquery-validate/jquery.validate.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css">
    <link rel="stylesheet" href="/css/register.css">
    <script>
        //页面加载完毕
        $(function () {
            //jQuery-validateton:表单验证
            $("#registerForm").validate({
                //校验规则
                rules:{
                    //针对具体输入框,nickName是name属性
                    nickName:{
                        required:true,//非空
                        rangelength:[5,10] //输入长度必须到5到10之间
                    },
                    confirmPwd:{
                        required:true, //非空
                        equalTo:"#password" //#表示id选择器,两次密码输入必须一致
                    }
                },
                messages:{
                    nickName:{
                        required:"昵称不能为空",
                        rangelength:"昵称的长度必须在5到10之间"
                    },
                    confirmPwd:{
                        required:"密码不能为空", //非空
                        equalTo:"密码不一致" //#表示id选择器,两次密码输入必须一致
                    }
                }
            })
            //dialog 弹窗
            $("#registerForm").ajaxForm(function (data) {
                if (data.success) {
                    //提示注册成功,然后留下登录按钮
                    $(document).dialog({
                        type: 'confirm',
                        style: 'ios',
                        content: '注册成功',
                        buttons: [{
                            name: '马上去登录',
                            callback: function () {
                                window.location.href = "login.html";
                            }
                        }]
                    });
                } else {
                    $(document).dialog({
                        titleText: '温馨提示',
                        content: data.msg
                    })
                }
            })

        })

    </script>
</head>
<body>

<div class="container">
    <h5>注册</h5>
    <div class="card card-container ">
        <i id="profile-img" class="fa fa-user-plus fa-5x profile-img" aria-hidden="true"></i>
        <form class="form-signin" id="registerForm" action="/users" method="post">
            <input type="text" name="nickName" class="form-control badge-pill" placeholder="昵称">
            <input type="email" name="email" class="form-control badge-pill" placeholder="邮箱">
            <input id="password" type="password" name="password" class="form-control badge-pill" placeholder="密码">
            <input type="password" name="confirmPwd" class="form-control badge-pill" placeholder="确认密码">
            <button class="btn btn-lg badge-pill" type="submit">注册</button>
        </form>
    </div>
    <a href="login.html" class="registerLink">
        已经有账号了？点击此处登录
    </a>
</div>

</body>
</html>
